﻿Public Class RSSElementPanel
  Inherits System.Windows.Forms.Panel

  Private WithEvents _pb As PictureBox
  Private WithEvents _name As Label
  Private WithEvents _date As Label
  Private WithEvents _download As New Button

  Private _config As Configuration = Configuration.GetObject
  Private _w As DownloadabeWallpaper

  Public Sub New(ByVal w As DownloadabeWallpaper)
    _w = w
    Me.Size = New Size(480, 100)

    Dim i As Image = Utils.GetPreviewImage(w)
    _pb = New PictureBox
    _pb.Size = New Size(i.Size.Width + 1, i.Height)
    _pb.Location = New Point(3, 3)
    _pb.Image = i

    Me.Size = New Size(480, i.Height + 5)

    '_pb.BorderStyle = Windows.Forms.BorderStyle.FixedSingle
    _pb.SizeMode = PictureBoxSizeMode.Zoom
    Me.Controls.Add(_pb)

    _name = New Label
    _name.Location = New Point(160, 17)
    _name.Text = w.Filename 'Utils.UCase(w.name)
    _name.AutoSize = True
    Me.Controls.Add(_name)

    _date = New Label
    _date.Location = New Point(160, 40)
    _date.Text = w.OrgaID 'w.Datum.ToShortDateString
    _date.Visible = False
    Me.Controls.Add(_date)

    _download = New Button
    _download.Size = New Size(160, 23)
    _download.Location = New Point(160, 63)
    _download.Text = "Download"
    _download.FlatStyle = FlatStyle.Flat 

    Me.Controls.Add(_download)

    Me.Refresh()
  End Sub

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _download.Click
    Cursor = Cursors.WaitCursor
    _w.DownloadFile()
    _download.Enabled = False
    Refresh()
    Cursor = Cursors.Default
  End Sub

  Private Sub PB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _pb.Click 
    Dim sbsf As new SkinsBeStartForm 
    sbsf.Text = _w.Filename 
    'sbsf.WebBrowser1.Navigate("http://wallpaper.skins.be/" & _w.Name & "/" & _w.OrgaID & "/" & Configuration.GetObject.Resolution & "/")
    sbsf.Show(MdiMain.DockPanel1)
  End Sub

  Private Sub PB_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _pb.MouseEnter 
    Cursor = Cursors.Hand 
  End Sub

  Private Sub PB_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _pb.MouseLeave
    Cursor = Cursors.Default
  End Sub

  Public Property ModelDate() As Date
    Get
      Return Date.Parse(_date.Text)
    End Get
    Set(ByVal value As Date)
      _date.Text = value.ToShortDateString()
    End Set
  End Property

  Public Property ModelName() As String
    Get
      Return _name.Text
    End Get
    Set(ByVal value As String)
      _name.Text = value
    End Set
  End Property

  Public Property PictureBox() As PictureBox
    Get
      Return _pb
    End Get
    Set(ByVal value As PictureBox)
      _pb = value
    End Set
  End Property

End Class
